﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using System.Data;

namespace DbManager
{
    /// <summary>
    /// 封装的sql语句查询类
    /// </summary>
    public abstract class DbQuery : DbDataBase, IQuery
    {
        #region 字段
        private DbCommand _dbcmd;
        #endregion
        #region 属性
        public DbCommand dbcommnd
        {
            get
            {
                return _dbcmd;
            }
        }
        protected string SQL { get; set; }
        #endregion
        #region 公开的方法
        /// <summary>
        /// 抽象设置DbCommand属性字段方法
        /// </summary>
        protected abstract DbCommand SetParameters();
        /// <summary>
        /// 实现IQuery接口方法,返回一个数据集
        /// </summary>
        public virtual DataSet Query()
        {
            #region
            DataSet set = null;
            _dbcmd = SetParameters();
            try
            {
                set = ExecuteDataSet(_dbcmd);
            }
            catch (Exception exception)
            {
                throw (exception);
            }
            return set;
            #endregion
        }
        #endregion
    }
}
